package phase03.module01.code;

import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

/**
 * @author 张富强
 * 利用mapper自身在分区时对key进行排序，直接将需要排序的每行数据设为输出key，让shuffle到reducer数据已经是排好序的
 */
public class SortNumbersMapper extends Mapper<LongWritable, Text, IntWritable, NullWritable> {
    private IntWritable val = new IntWritable();
    @Override
    protected void map(LongWritable key, Text value, Mapper<LongWritable, Text, IntWritable, NullWritable>.Context context) throws IOException, InterruptedException {
        Integer v = Integer.parseInt(value.toString());
        System.out.println(v);
        val.set(v);
        context.write(val, NullWritable.get());
    }
}
